/**
 * related to repairInfo.ui
 * 
 * @Author : 2037630@163.com
 * @Timestamp : 2017-04-19
 */
var nf = sm("do_Notification");
var Controller = require("core/controller");
var log = require("util/log")
var navigate = require("util/navigate")
var router = require("config/router")
var server = require('config/server');
var net = require("util/net");
var page = sm("do_Page");
var clxx_userName = ui('clxx_userName');
var clxx_userTel = ui('clxx_userTel');
var clxx_detailAddr = ui('clxx_detailAddr');
var clxx_wexinNumb = ui('clxx_wexinNumb');
var clxx_qqNumb = ui('clxx_qqNumb');
var clxx_remarkInfo = ui('clxx_remarkInfo');
var city = require("module/cityModule")
var deviceMou=require("module/deviceModule")
Controller({
	config : {
		name : '修复信息',
		header : {
			title : '修复信息',
			right : {
				text : '保存',
				handle : function() {
					if(this.data.userInfo.clxx_userName.length<1){
						deviceMou.isIOS===true?nf.toast('姓名不能为空', 150, 850):nf.toast('姓名不能为空')
					}else if(this.data.userInfo.clxx_userTel.length<=8){
						deviceMou.isIOS===true?nf.toast('请输入电话号码', 150, 850):nf.toast('请输入电话号码')
					}else if (this.data.userInfo.clxx_detailAddr.length<5) {
						deviceMou.isIOS===true?nf.toast('地址的长度不得少于5位', 150, 850):nf.toast('地址的长度不得少于5位')
					}
					else{
						this.toSubmit()
					}
				}
			}
		}
	},
	mapping : {
		"combo.items" : "userInfo.comboData|getTypeCodeData",
		"combo.value" : "userInfo.comboValue",
		"com_telState.items" : "userInfo.com_telState|getTypeCodeData",
		"com_telState.value" : "userInfo.com_telStateValue",

		"com_addProv.items" : "userInfo.com_addProv|getTypeCodeData",
		"com_addProv.value" : "userInfo.com_addProvValue",
		"com_addCity.items" : "userInfo.com_addCity|getTypeCodeData",
		"com_addCity.value" : "userInfo.com_addCityValue",
		"com_addArea.items" : "userInfo.com_addArea|getTypeCodeData",
		"com_addArea.value" : "userInfo.com_addAreaValue",

		"com_addressType.items" : "userInfo.com_addressType|getTypeCodeData",
		"com_addressType.value" : "userInfo.com_addressTypeValue",
		"com_addresState.items" : "userInfo.com_addresState|getTypeCodeData",
		"com_addresState.value" : "userInfo.com_addresStateValue",
		"clxx_userName.text" : "userInfo.clxx_userName",
		"clxx_userTel.text" : "userInfo.clxx_userTel",
		"clxx_detailAddr.text" : "userInfo.clxx_detailAddr",
		"clxx_wexinNumb.text" : "userInfo.clxx_wexinNumb",
		"clxx_qqNumb.text" : "userInfo.clxx_qqNumb",
		"clxx_remarkInfo.text" : "userInfo.clxx_remarkInfo"
	},
	data : {
		userInfo : {
			comboData : "0034",
			comboValue : "145",
			com_telState : "0023",
			com_telStateValue : "83",
			com_addProv : "",
			com_addProvValue : "",
			com_addCity : "",
			com_addCityValue : "",
			com_addArea : "",
			com_addAreaValue : "",
			com_addressType : "0024",
			com_addressTypeValue : "88",
			com_addresState : "0025",
			com_addresStateValue : "93",
			clxx_userName : "",
			clxx_userTel : "",
			clxx_detailAddr : "",
			clxx_wexinNumb : "",
			clxx_qqNumb : "",
			clxx_remarkInfo : ""
		}
	},
	ui : {
		com_addProv : "com_addProv",
		com_addCity : "com_addCity",
		com_addArea : "com_addArea",
		icon_cancleTel:"icon_cancleTel",
		clxx_userTel:"clxx_userTel"
	},
	event : {
		icon_cancleTel:{
			'touch' : function() {
				this.ui.clxx_userTel.text=""
			}
		},
		clxx_userTel:{
			'textChanged' : function() {
				if (this.data.userInfo.clxx_userTel.length<=0) {
//					this.ui.test.bgColor="#28313eFF"
//					this.ui.icon_cancle.iconf  administrator
					this.ui.icon_cancleTel.visible=false
				}else {
					this.ui.icon_cancleTel.visible=true
				}
			}
		}
	},
	methods : {
		toSubmit : function() {
			log.info(588,this.data.dataRepInfo)
			var sendData = {
				addressList : [ {
					address : this.data.userInfo.clxx_detailAddr,
					addressStatus : this.data.userInfo.com_addresStateValue,
					addressType : this.data.userInfo.com_addressTypeValue,
					cityId : city.getCityId(this.ui.com_addCity),
					countyId : city.getCityId(this.ui.com_addArea),
					provinceId : city.getCityId(this.ui.com_addProv)
				} ],
				customerInformationId : this.data.dataRepInfo,
				name : this.data.userInfo.clxx_userName,
				phoneList : [ {
					phone : this.data.userInfo.clxx_userTel,
					phoneStatus : this.data.userInfo.com_telStateValue
				} ],
				relation : this.data.userInfo.comboValue,
				remark : this.data.userInfo.clxx_remarkInfo,
				 socialList: []
			}
			
			if(!!this.data.userInfo.clxx_wexinNumb){
				sendData.socialList.push({
					  socialNum: this.data.userInfo.clxx_wexinNumb,
				      socialType: 100
				})
			}
			if(!!this.data.userInfo.clxx_qqNumb){
				sendData.socialList.push({
					 socialNum: this.data.userInfo.clxx_qqNumb,
					  socialType: 101
				})
			}
			if(sendData.socialList.length===0){
				sendData.socialList.push({
					 socialNum:"",
					  socialType: ""
				})
			}
			log.info(5555, this.data.userInfo.clxx_userName);
			net.send({
						server : server.organization.saveNewRepairInfo,
						data : sendData,
						success : function() {
							this.refresh('$')
							nf.toast("提交成功")
							navigate.back("6666")
						},
						error : function(data) {
							nf.toast(data.reason)
						},
						scope : this
					})
		}
	},
	loaded : function(data) {
		this.data.dataRepInfo = data
		city.init(this.ui.com_addProv, this.ui.com_addCity,this.ui.com_addArea)
	},
})